package com.xsh.subsynth;

import android.content.Context;
import android.util.Log;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class SubSynthEventHandler
{
    String tag = SubSynthEventHandler.class.getSimpleName();
    Class<?> SlEngine;
    public SubSynthEventHandler(Context ctx,Class<?> p_engine)
    {
        SlEngine = p_engine;
    }
    public void setOsc1Wave(int index) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException
    {
        Log.d(tag,"选择osc1：" + index);
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParamEnum",String.class,int.class);
        method.invoke(null,"setOsc1Wave",index);
    }
    public void setOsc2Wave(int index) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException
    {
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParamEnum",String.class,int.class);
        method.invoke(null,"setOsc2Wave",index);
    }
    public void setFilter(int index) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException
    {
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParamEnum",String.class,int.class);
        method.invoke(null,"setFilter",index);
    }
    public void setCutOff(int progress) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParamEnum",String.class,int.class);
        method.invoke(null,"setFilter",progress);
    }
    public void setRes(int progress) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException
    {
        //double res = progress / 100.0;
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParamEnum",String.class,int.class);
        method.invoke(null,"setRes",progress);
    }

    public void setLfoType(int index) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException
    {
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParamEnum",String.class,int.class);
        method.invoke(null,"setLfoType",index);
    }

    public void setLfoSpeed(int speed) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException
    {
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParamEnum",String.class,int.class);
        method.invoke(null,"setLfoSpeed",speed);
    }
    public void setLfoAmp(int amp) throws InvocationTargetException, IllegalAccessException, NoSuchMethodException
    {
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParam",String.class,double.class);
        method.invoke(null,"setLfoAmp",(double)amp);
    }
    public void setAmp(int progress) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        double amp = progress/100.0;
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParam",String.class,double.class);
        method.invoke(null,"setAmp",amp);
    }

    public void toggleFilter(boolean a) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParamBool",String.class,boolean.class);
        method.invoke(null,"toggleFilter",a);
    }
    public void toggleLfo(boolean a) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        Method method = SlEngine.getDeclaredMethod("changeActiveInsParamBool",String.class,boolean.class);
        method.invoke(null,"toggleLfo",a);
    }

}
